﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CSP.Dao.IObjectDaos.CSP;
using CSP.Dao.CommonDao;
using CSP.DataAccess;
using CSP.Model.CSP;

namespace CSP.Dao.ObjectDaos.CSP
{
    public class ServiceInfoAgeGroupRelDao : CSPCommonDao, IServiceInfoAgeGroupRelDao
    {

        public ServiceInfoAgeGroupRelDao(CSPContext context, bool isTransaction = false)
            : base(context, isTransaction)
        { }

        public ICollection<Model.CSP.ServiceInfoAgeGroupRel> FindAll()
        {
            return _context.ServiceInfoAgeGroupRels.ToArray();
        }

        public Model.CSP.ServiceInfoAgeGroupRel GetDataById(int id)
        {
            return _context.ServiceInfoAgeGroupRels.FirstOrDefault(a => a.id == id);
        }

        public ICollection<Model.CSP.ServiceInfoAgeGroupRel> GeDatatByIds(int[] Ids)
        {
            return _context.ServiceInfoAgeGroupRels.Where(a => Ids.Contains(a.id)).ToArray();
        }

        public void Add(Model.CSP.ServiceInfoAgeGroupRel obj)
        {
            _context.ServiceInfoAgeGroupRels.Add(obj);
            _context.SaveChanges();
        }

        public void Update(Model.CSP.ServiceInfoAgeGroupRel obj)
        {
            ServiceInfoAgeGroupRel serviceInfoAgeGroupRel = GetDataById(obj.id);
            if (serviceInfoAgeGroupRel != null)
            {
                serviceInfoAgeGroupRel = obj;
            }
            _context.SaveChanges();
        }

        public ServiceInfoAgeGroupRel DeleteById(int id)
        {
            ServiceInfoAgeGroupRel serviceInfoAgeGroupRel = GetDataById(id);
            _context.ServiceInfoAgeGroupRels.Remove(serviceInfoAgeGroupRel);
            _context.SaveChanges();

            return serviceInfoAgeGroupRel;
        }
    }
}
